<template>
	<!-- 项目任务节点实施情况 -->
	<div class="">
		<CommonTitle class="m-b20" titleName="项目任务节点实施情况"> </CommonTitle>
		<div class="title_top d-flex m-b20">
			所属项目： <span class="m-l10 style-font">{{ form.projectName }}</span>
			<el-divider class="m-l10 m-r10" direction="vertical" />
			所属实施阶段:<span class="m-l10 style-font"
				>{{ form.projectStageName }}
			</span>
			<el-divider class="m-l10 m-r10" direction="vertical" />
			所属任务:<span class="m-l10 style-font">{{ form.taskName }} </span>
			<el-divider class="m-l10 m-r10" direction="vertical" />
			项目计划时间范围：
			<span class="m-l10 style-font"
				>{{ form.planStartTime }} 至 {{ form.planEndTime }}</span
			>
		</div>
		<tableIndex
			:tableData="tableData"
			:tableHead="tableHead"
			:isSelection="false"
			:isIndex="true"
			:height="'500'"
			:page="state.page"
			:notSearch="true"
			:isPaging="false"
		>
			<template #operate>
				<el-table-column label="操作" width="350" fixed="right" align="center">
<!--					<template #default="{ row }">
						<el-button
							v-if="row.actionName=='上传实施成果' && row.status!==2"
							size="small"
							type="primary"
							@click="nodeHandler('提交', row)"
							>提交实施成果</el-button
						>
						<el-button
							v-if="row.actionName=='上传实施成果'  && row.status===2"
							size="small"
							type="primary"
							@click="nodeHandler('查看', row)"
							>查看实施成果</el-button
						>
					</template>-->

					<template #default="{ row }">
						<el-button
								v-if="
                  (row.status == -1 &&
                    row.auditStatus == 2 &&
                    row.isOverdue == 1) ||
                  (row.status == -1 &&
                    row.auditStatus == 0 &&
                    row.isOverdue == 0)
                "
								size="small"
								class="update"
								type="primary"
								@click="addHandler(row)"
						>{{ row.actionName }}</el-button
						>

						<el-button
								v-if="
                  row.status > 0 ||
                  (row.businessAuditStatus == 3 && row.status == -1)
                "
								size="small"
								class="update"
								type="primary"
								@click="lookHandler(row)"
						>查看结果</el-button
						>
						<el-button
								v-if="
                  row.isOverdue == 1 &&
                  row.status == -1 &&
                  (row.auditStatus == 0 || row.auditStatus == 3)
                "
								size="small"
								class="update"
								type="primary"
								@click="anticipateHandler(row, '逾期上报')"
						>逾期上报</el-button
						>
						<el-button
								v-if="row.auditStatus == 1 && row.status == -1"
								size="small"
								class="update"
								type="primary"
								@click="anticipateHandler(row, '审核')"
						>审核</el-button
						>
					</template>
				</el-table-column>
			</template>
		</tableIndex>
	</div>

  <!--实施成果	-->
	<over-dialog
		ref="overDialogRef"
		@refreshList="projectTaskList"
	/>

	<!--	上传合同扫描件 -->
	<contractDialog
			ref="contractdialog"
			@refreshList="projectTaskList"
	></contractDialog>

	<!-- 逾期上报 -->
	<anticipatLoading
			@projectTaskList="projectTaskList"
			ref="anticipatLoadingRef"
	></anticipatLoading>
</template>

<script setup>
import { ref, reactive, onMounted } from "vue";
import CommonTitle from "@/components/CommonTitle.vue";
import TableIndex from "@/components/table/index.vue";
import { useRoute, useRouter } from "vue-router";
import { getURLhandler } from "@/views/constructionProjectManage/static/utools.js";

//实施成果
import OverDialog from '@/views/constructionProjectManage/mytobeDone/components/overDialog.vue'
// 逾期上报
import AnticipatLoading from '@/views/constructionProjectManage/projectImplementationTask/anticipatLoading.vue'
//合同扫描
import ContractDialog from '@/views/constructionProjectManage/mytobeDone/components/contractDialog.vue'


import {
	projectApi,
	projectListApi,
	projectConfigApi,
	qualitySupervision,
	department, projectTask,
} from "@/api/project";
let router = useRouter();
let route = useRoute();
const projectId = getURLhandler(route.path).projectId;
const projectTaskId = getURLhandler(route.path).projectTaskId;

const state = reactive({
	form: {},
	projectStageId: "",
	page: {
		page: 1,
		pageSize: 10,
		total: 0,
	},
});
const tableHead = ref([
	{
		prop: "status",
		label: "节点状态",
		formatter: (row) => {
			let str = "";
			// -1-未开始 1-进行中 2-已完成 3-停工 4-其他
			switch (row.status) {
				case -1:
					str = "未开始";
					break;
				case 1:
					str = "进行中";
					break;
				case 2:
					str = "已完成";
					break;
				case 3:
					str = "停工";
          break;
        case 4:
          str = "其他";
          break;
				default:
					break;
			}
			return str;
		},
	},
	{
		prop: "itemName",
		label: "工作明细",
	},
	{
		prop: "responsibleDepartmentName",
		label: "责任部门",
	},
	{
		prop: "responsibleUserName",
		label: "责任人",
	},
	{
		prop: "planStartTime",
		label: "节点计划开始时间",
		formatter: (row) => {
			return  row.planStartTime?row.planStartTime.split(' ')[0]:'-'
		}
	},
	{
		prop: "planEndTime",
		label: "节点计划结束时间",
	},
	{
		prop: "actionName",
		label: "实施行为类型",
	},
]);
const tableData = ref([]);
const form = ref({
	projectName: "",
	responsibleDepartmentName: "",
	responsibleUserName: "",
	predictStartTime: "",
	predictEndTime: "",
	projectId:""
});
const handel = () => {};
const getPage = () => {
	projectConfigApi.getItemList(projectTaskId).then((res) => {
		tableData.value = res.data;
	});
};
const getInfoData = () => {
	projectListApi.getprojectByid(projectId).then((res) => {
		const { code, data, msg } = res;
		if (code == 200) {
			form.value = data;
		}
	});
};

const overDialogRef = ref(null);
const nodeHandler = (type,row) => {
	overDialogRef.value.state.centerDialogVisible = true
	overDialogRef.value.state.businessId = row.businessId
	overDialogRef.value.state.projectTaskId = row.projectTaskId
	overDialogRef.value.state.itemId = row.itemId
	if(type==='提交'){
		overDialogRef.value.state.type = 0
	}
	if(type==='查看'){
		overDialogRef.value.state.type = 1
	}
};

const projectTaskList = () => {
	getPage();
}


/**
 * 操作
 * @param row
 */
const contractdialog = ref(null);
const addHandler = (row) => {
	switch (row.actionId) {
		case '7':
			router.push({
				path: `/constructionProjectManage/projectSupervision/components/contract/projectId=${
						form.value.projectId
				}&projectTaskId=${row.projectTaskId}&itemId=${
						row.itemId
				}&isLook=${0}&type=0`
			})
			break
		case '6':
			router.push({
				path: `/constructionProjectManage/projectSupervision/components/service/projectId=${
						form.value.projectId
				}&itemId=${row.itemId}&projectTaskId=${row.projectTaskId}&isLook=${0}`
			})
			break
		case '3':
			router.push({
				path: `/constructionProjectManage/projectSupervision/components/topic/projectId=${
						form.value.projectId
				}&itemId=${row.itemId}&projectTaskId=${row.projectTaskId}&isLook=${0}`
			})
			// 发起招采需求议题请示
			break
		case '4':
			router.push({
				path: `/constructionProjectManage/projectSupervision/components/approve/projectId=${
						form.value.projectId
				}&itemId=${row.itemId}&projectTaskId=${row.projectTaskId}&isLook=${0}`
			})
			break
		case '5':
			router.push({
				path: `/constructionProjectManage/projectImplementationTask/decisionIndex/projectId=${
						form.value.projectId
				}&projectTaskId=${row.projectTaskId}&itemId=${row.itemId}&isLook=${0}`
			})
			break
		case '8':
			router.push({
				path: `/constructionProjectManage/projectImplementationTask/callForBids/projectId=${
						form.value.projectId
				}&projectTaskId=${row.projectTaskId}&itemId=${
						row.itemId
				}&isLook=${0}&type=1`
			})
			break
		case '9':
			contractdialog.value.state.dialogVisible = true
			contractdialog.value.state.businessId = row.businessId
			contractdialog.value.state.projectTaskId = row.projectTaskId
			contractdialog.value.state.type = 0
			contractdialog.value.state.itemId = row.itemId
			break
		case '1':
			overDialogRef.value.state.centerDialogVisible = true
			overDialogRef.value.state.businessId = row.businessId
			overDialogRef.value.state.projectTaskId = row.projectTaskId
			overDialogRef.value.state.type = 0
			overDialogRef.value.state.itemId = row.itemId
			break
		case '2':
			router.push({
				path: `/constructionProjectManage/projectImplementationTask/organizeAMeeting/projectId=${
						form.value.projectId
				}&projectTaskId=${row.projectTaskId}&itemId=${row.itemId}&isLook=${0}`
			})
			break;
	}
}

/**
 * 查看结果
 * @param row
 */
const lookHandler = (row) => {
	switch (row.actionId) {
		case '7':
			//合同初稿
			router.push({
				path: `/constructionProjectManage/projectSupervision/components/contract/projectId=${
						form.value.projectId
				}&itemId=${row.itemId}&projectTaskId=${row.projectTaskId}&itemId=${
						row.itemId
				}&isLook=${1}&type=0`
			})
			break
		case '6':
			router.push({
				path: `/constructionProjectManage/projectSupervision/components/service/projectId=${
						form.value.projectId
				}&itemId=${row.itemId}&projectTaskId=${row.projectTaskId}&isLook=${1}`
			})
			break
		case '3':
			router.push({
				path: `/constructionProjectManage/projectSupervision/components/topic/projectId=${
						form.value.projectId
				}&itemId=${row.itemId}&projectTaskId=${row.projectTaskId}&isLook=${1}`
			})
			// 查看招采需求议题请示
			break
		case '4':
			router.push({
				path: `/constructionProjectManage/projectSupervision/components/approve/projectId=${
						form.value.projectId
				}&itemId=${row.itemId}&projectTaskId=${row.projectTaskId}&isLook=${1}`
			})

			break
		case '5':
			router.push({
				path: `/constructionProjectManage/projectImplementationTask/decisionIndex/projectId=${
						form.value.projectId
				}&projectTaskId=${row.projectTaskId}&itemId=${row.itemId}&isLook=${1}`
			})
			break
		case '8':
			router.push({
				path: `/constructionProjectManage/projectImplementationTask/callForBids/projectId=${
						form.value.projectId
				}&projectTaskId=${row.projectTaskId}&itemId=${
						row.itemId
				}&isLook=${1}&type=1`
			})
			break
		case '9':
			contractdialog.value.state.dialogVisible = true
			contractdialog.value.state.businessId = row.businessId
			contractdialog.value.state.projectTaskId = row.projectTaskId
			contractdialog.value.state.type = 1
			contractdialog.value.state.itemId = row.itemId
			break
		case '1':
			overDialogRef.value.state.centerDialogVisible = true
			overDialogRef.value.state.businessId = row.businessId
			overDialogRef.value.state.projectTaskId = row.projectTaskId
			overDialogRef.value.state.type = 1
			overDialogRef.value.state.itemId = row.itemId
			break
		case '2':
			router.push({
				path: `/constructionProjectManage/projectImplementationTask/organizeAMeeting/projectId=${
						form.value.projectId
				}&projectTaskId=${row.projectTaskId}&itemId=${row.itemId}&isLook=${1}`
			})
		break;
	}
}

/**
 * 逾期上报
 * @param row
 * @param type
 */
const anticipatLoadingRef = ref(null);
const anticipateHandler = (row, type) => {
	anticipatLoadingRef.value.open(row, type)
}

/**
 * 获取任务信息
 */
const getTaskInfo = () => {
	projectTask.getTaskInfo({projectTaskId:projectTaskId}).then(res=>{
		if(res.code==='200'){
			form.value = res.data;
		}
	})
}

onMounted(() => {
	// getInfoData();
	getTaskInfo();
	getPage();
});
</script>
<style lang="scss" scoped>
.style-font{
	font-weight: 400;
}

.title_top {
	font-size: 14px;
	font-family: SourceHanSansCN-Medium, SourceHanSansCN;
	font-weight: 700;
	color: #1a1a1a;
}
</style>
